package com.hb.trade.server.project.evaluation.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hb.core.pojo.project.evaluation.dto.EvaluationBidSectionParam;
import com.hb.core.pojo.project.evaluation.dto.EvaluationThirdDTO;
import com.hb.core.pojo.project.evaluation.entity.*;
import com.hb.core.pojo.project.evaluation.vo.EvaluationOpeningScheduleVO;
import com.hb.core.pojo.project.evaluation.vo.EvaluationProjectAndSectionInfoVO;
import com.hb.core.pojo.project.evaluation.vo.EvaluationReviewItemFlowNodesVO;
import com.hb.core.pojo.project.file.dto.ReviewItemFirstDto;
import com.hb.core.pojo.project.file.dto.ReviewItemSecondDto;
import com.hb.core.pojo.project.file.dto.ReviewItemThirdDto;
import com.hb.core.pojo.project.file.entity.ReviewItemFirst;
import com.hb.core.pojo.project.file.entity.ReviewItemSecond;
import com.hb.core.pojo.project.opening.entity.BidOpeningSchedule;
import com.hb.core.pojo.project.opening.entity.OpeningBidTender;
import com.hb.core.pojo.project.proj.entity.*;
import com.hb.core.pojo.project.proj.enums.BidWayEnum;
import com.hb.core.pojo.project.section.dto.BidSectionTenderDTO;
import com.hb.core.pojo.project.section.dto.ClarifyDTO;
import com.hb.core.pojo.project.section.entity.BidSection;
import com.hb.core.pojo.project.section.entity.TradeSecondQuotationBidInfo;
import com.hb.core.pojo.project.section.mapper.TradeSecondQuotationBidInfoMapper;
import com.hb.trade.server.project.evaluation.service.*;
import com.hb.trade.server.project.file.service.ReviewItemFirstService;
import com.hb.trade.server.project.file.service.ReviewItemSecondService;
import com.hb.trade.server.project.file.service.ReviewItemThirdService;
import com.hb.trade.server.project.opening.service.BidOpeningScheduleService;
import com.hb.trade.server.project.opening.service.OpeningBidHallService;
import com.hb.trade.server.project.opening.service.OpeningBidTenderService;
import com.hb.trade.server.project.proj.service.ProjectService;
import com.hb.trade.server.project.section.service.raw.BidSectionService;
import com.hb.trade.server.project.section.service.raw.BidSectionTenderService;
import com.hb.trade.server.project.section.service.raw.ClarifyService;
import org.fzzn.core.model.enums.LogicEnum;
import org.fzzn.core.util.MsgUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jinhaolin
 * @date 2022/4/15 0015 11:19
 **/
@Service
public class EvaluationServiceImpl implements EvaluationService {

    @Resource
    private TradeSecondQuotationBidInfoMapper tradeSecondQuotationBidInfoMapper;

    protected final BidSectionService bidSectionService;
    protected final ClarifyService clarifyService;
    protected final BidOpeningScheduleService bidOpeningScheduleService;
    protected final ReviewItemFirstService reviewItemFirstService;
    protected final EvaluationCommitteeMembersService evaluationCommitteeMembersService;
    protected final EvaluationSummaryService evaluationSummaryService;
    protected final EvaluationSecondService evaluationSecondService;
    protected final EvaluationThirdService evaluationThirdService;
    protected final ReviewItemSecondService reviewItemSecondService;
    protected final ReviewItemThirdService reviewItemThirdService;
    protected final ProjectService projectService;
    protected final BidSectionTenderService bidSectionTenderService;
    protected final OpeningBidHallService openingBidHallService;
    protected final OpeningBidTenderService openingBidTenderService;

    public EvaluationServiceImpl(BidSectionService bidSectionService,
                                 ClarifyService clarifyService,
                                 BidOpeningScheduleService bidOpeningScheduleService,
                                 ReviewItemFirstService reviewItemFirstService,
                                 EvaluationCommitteeMembersService evaluationCommitteeMembersService,
                                 EvaluationSummaryService evaluationSummaryService,
                                 ReviewItemSecondService reviewItemSecondService,
                                 EvaluationSecondService evaluationSecondService,
                                 EvaluationThirdService evaluationThirdService,
                                 ReviewItemThirdService reviewItemThirdService,
                                 ProjectService projectService,
                                 BidSectionTenderService bidSectionTenderService,
                                 OpeningBidHallService openingBidHallService,
                                 OpeningBidTenderService openingBidTenderService) {
        this.bidSectionService = bidSectionService;
        this.clarifyService = clarifyService;
        this.bidOpeningScheduleService = bidOpeningScheduleService;
        this.reviewItemFirstService = reviewItemFirstService;
        this.evaluationCommitteeMembersService = evaluationCommitteeMembersService;
        this.evaluationSummaryService = evaluationSummaryService;
        this.reviewItemSecondService = reviewItemSecondService;
        this.evaluationSecondService = evaluationSecondService;
        this.evaluationThirdService = evaluationThirdService;
        this.reviewItemThirdService = reviewItemThirdService;
        this.projectService = projectService;
        this.bidSectionTenderService = bidSectionTenderService;
        this.openingBidHallService = openingBidHallService;
        this.openingBidTenderService = openingBidTenderService;
    }


    @Override
    public EvaluationProjectAndSectionInfoVO bidProjectAndSectionInfo(EvaluationBidSectionParam evaluationBidSectionParam) {
        Long sectionId = evaluationBidSectionParam.getSectionId();

        // 获取项目和标段信息
        EvaluationProjectAndSectionInfoVO evaluationProjectAndSectionInfoVO = bidSectionService.bidProjectAndSectionInfoBySectionId(sectionId);

        // 获取澄清公告列表
        List<ClarifyDTO> listClarifyDTO = clarifyService.listClarifyBySectionId(sectionId);
        evaluationProjectAndSectionInfoVO.setListClarifyDTO(listClarifyDTO);

        // 获取开标一览表
        List<BidOpeningSchedule> listBidOpeningSchedule = bidOpeningScheduleService.listBySectionId(sectionId);
        evaluationProjectAndSectionInfoVO.setListBidOpeningSchedule(listBidOpeningSchedule);

        return evaluationProjectAndSectionInfoVO;
    }

    @Override
    public EvaluationReviewItemFlowNodesVO reviewItemFlowNodes(EvaluationBidSectionParam evaluationBidSectionParam) {
        Long sectionId = evaluationBidSectionParam.getSectionId();
        Long expertId = evaluationBidSectionParam.getExpertId();

        EvaluationReviewItemFlowNodesVO evaluationReviewItemFlowNodesVO = new EvaluationReviewItemFlowNodesVO();
        evaluationReviewItemFlowNodesVO.setSectionId(sectionId);

        // 是否为组长
        Integer chairmanFlag = evaluationCommitteeMembersService.getById(expertId).getChairmanFlag();
        evaluationReviewItemFlowNodesVO.setChairmanFlag(chairmanFlag);

        // 是否包含多轮报价(只有竞争性谈判、竞争性磋商有多轮报价)
        AbstractProject project = projectService.getProjectBySectionId(sectionId);
        if (project.getBidWay().equals(BidWayEnum.NEG.getCode())
                || project.getBidWay().equals(BidWayEnum.CON.getCode())) {
            evaluationReviewItemFlowNodesVO.setMultiPriceFlag(1);
        } else {
            evaluationReviewItemFlowNodesVO.setMultiPriceFlag(0);
        }

        // 评标状态
        QueryWrapper<EvaluationSummary> wrapper = new QueryWrapper<>();
        wrapper.eq("section_id", sectionId);
        EvaluationSummary evaluationSummary = evaluationSummaryService.getOne(wrapper, false);
        if (evaluationSummary != null) {
            evaluationReviewItemFlowNodesVO.setEvaluationStatus(evaluationSummary.getEvaluationStatus());
        } else {
            evaluationReviewItemFlowNodesVO.setEvaluationStatus(1);
        }

        // 生成评标流程节点
        List<EvaluationReviewItemNode> evaluationReviewItemNodeList = createReviewItemFlowNodes(sectionId, expertId);
        evaluationReviewItemFlowNodesVO.setListEvaluationReviewItemNode(evaluationReviewItemNodeList);

        return evaluationReviewItemFlowNodesVO;
    }

    @Override
    public EvaluationReviewItemFlowNodesVO reviewItemFlowNodesOffline(EvaluationBidSectionParam evaluationBidSectionParam) {
        Long sectionId = evaluationBidSectionParam.getSectionId();
        Long expertId = evaluationBidSectionParam.getExpertId();

        EvaluationReviewItemFlowNodesVO evaluationReviewItemFlowNodesVO = new EvaluationReviewItemFlowNodesVO();
        evaluationReviewItemFlowNodesVO.setSectionId(sectionId);

        // 是否包含多轮报价(只有竞争性谈判、竞争性磋商有多轮报价)
        AbstractProject project = projectService.getProjectBySectionId(sectionId);
        if (project.getBidWay().equals(BidWayEnum.NEG.getCode())
                || project.getBidWay().equals(BidWayEnum.CON.getCode())) {
            evaluationReviewItemFlowNodesVO.setMultiPriceFlag(1);
        } else {
            evaluationReviewItemFlowNodesVO.setMultiPriceFlag(0);
        }

        List<EvaluationReviewItemNode> evaluationReviewItemNodeList = new ArrayList<>();

        // 文件查看节点
        EvaluationReviewItemNode seeFileNode = new EvaluationReviewItemNode();
        seeFileNode.setNum(1);
        seeFileNode.setScoreSubmitFlag(1);
        seeFileNode.setFirstReviewItemType(0);
        seeFileNode.setSecondReviewItemName("文件查看");
        evaluationReviewItemNodeList.add(seeFileNode);

        // 报价评审节点
        if (evaluationReviewItemFlowNodesVO.getMultiPriceFlag().equals(1)) {
            EvaluationReviewItemNode offerNode = new EvaluationReviewItemNode();
            offerNode.setNum(2);

            // 是否结束报价
            // 查询多伦报价是否完成
            QueryWrapper<TradeSecondQuotationBidInfo> secondQuotationBidInfoQueryWrapper = new QueryWrapper<>();
            secondQuotationBidInfoQueryWrapper.lambda().eq(TradeSecondQuotationBidInfo::getSectionId, sectionId)
                    .eq(TradeSecondQuotationBidInfo::getEndType, "2");

            List<TradeSecondQuotationBidInfo> tradeSecondQuotationBidInfos = tradeSecondQuotationBidInfoMapper.selectList(secondQuotationBidInfoQueryWrapper);
            // 如果多伦报价结束则存库
            if (CollUtil.isNotEmpty(tradeSecondQuotationBidInfos)) {
                offerNode.setScoreSubmitFlag(1);
            }

            offerNode.setFirstReviewItemType(3);
            offerNode.setSecondReviewItemName("报价评审");
            evaluationReviewItemNodeList.add(offerNode);
        }

        evaluationReviewItemFlowNodesVO.setListEvaluationReviewItemNode(evaluationReviewItemNodeList);

        return evaluationReviewItemFlowNodesVO;
    }

    /**
     * 判断节点数据是否可修改，规则如下：
     * 1. 初步评审各评审项必须按照顺序来评审，上一个评审项未汇总，下一个评审项不允许提交数据
     * 2. 只有初步评审全部汇总完成以后，后面的详细评审、报价评审才可以进行。初步评审之后的评审项没有顺序。
     * @param sectionId
     * @param reviewItemId
     * @param expertId
     * @return
     */
    @Override
    public Boolean canNodeDataModify(Long sectionId, Long reviewItemId, Long expertId) {
        List<EvaluationReviewItemNode> reviewItemNodeList = createReviewItemFlowNodes(sectionId, expertId);

        ReviewItemSecond reviewItemScond = reviewItemSecondService.getById(reviewItemId);
        ReviewItemFirst reviewItemFirst = reviewItemFirstService.getById(reviewItemScond.getFirstReviewItemId());

        // 评审大项类型 1：初步评审 2：详细评审 3：报价评审
        int reviewItemType = reviewItemFirst.getFirstReviewItemType();

        // 当前节点数据是否可修改
        boolean canModify = true;

        if (reviewItemType == 1) {
            // 当前修改节点是初步评审:判断该节点之前的节点是否已经完成汇总
            for (EvaluationReviewItemNode reviewItemNode : reviewItemNodeList) {
                if (reviewItemNode.getSecondReviewItemId().equals(reviewItemId)) {
                    return canModify;
                } else {
                    if (reviewItemNode.getResultSummaryFlag().equals(0)) {
                        canModify = false;
                        return canModify;
                    }
                }
            }
        } else {
            // 当前修改节点是非初步评审:判断是否所有初步评审的节点都是已汇总状态
            for (EvaluationReviewItemNode reviewItemNode : reviewItemNodeList) {
                if (reviewItemNode.getFirstReviewItemType().equals(1)
                        && reviewItemNode.getResultSummaryFlag().equals(0)) {
                    canModify = false;
                    return canModify;
                }
            }
        }

        return canModify;
    }

    /**
     * 生成评标流程节点
     * @param sectionId
     * @param expertId
     * @return
     */
    private List<EvaluationReviewItemNode> createReviewItemFlowNodes(Long sectionId, Long expertId) {
        List<EvaluationReviewItemNode> evaluationReviewItemNodeList = new ArrayList<>();

        // 根据标段id获取评审流程包含哪几步
        List<ReviewItemFirstDto> reviewItemFirstDtoList = reviewItemFirstService.selectReviewItemBySectionId(sectionId);
        int num = 1;
        for (ReviewItemFirstDto reviewItemFirstDto : reviewItemFirstDtoList) {
            ReviewItemSecondDto reviewItemSecondParam = new ReviewItemSecondDto();
            reviewItemSecondParam.setFirstReviewItemId(reviewItemFirstDto.getId());
            List<ReviewItemSecondDto> reviewItemSecondDtoList = reviewItemSecondService.selectReviewItemSecondList(reviewItemSecondParam);

            for (ReviewItemSecondDto reviewItemSecondDto : reviewItemSecondDtoList) {
                Long secondReviewItemId = reviewItemSecondDto.getId();

                EvaluationReviewItemNode evaluationReviewItemNode = new EvaluationReviewItemNode();
                evaluationReviewItemNode.setNum(num);

                // 判断评审结果是否已全部提交
                int scoreSubmitFlag = 1;
                List<EvaluationSecond> evaluationSecondList = evaluationSecondService.findBySectionIdAndExpertIdAndSecondId(sectionId, expertId, secondReviewItemId);
                if (evaluationSecondList.size() == 0) {
                    scoreSubmitFlag = 0;
                } else {
                    for (EvaluationSecond evaluationSecond : evaluationSecondList) {
                        if (evaluationSecond.getEvaluationStatus() == 0) {
                            scoreSubmitFlag = 0;
                            break;
                        }
                    }
                }
                evaluationReviewItemNode.setScoreSubmitFlag(scoreSubmitFlag);

                // 判断是否已汇总
                int resultSummaryFlag = 1;
                List<EvaluationSecond> evaluationSecondSummaryList = evaluationSecondService.findBySectionIdAndSecondId(sectionId, secondReviewItemId);
                if (evaluationSecondSummaryList.size() == 0) {
                    resultSummaryFlag = 0;
                } else {
                    for (EvaluationSecond evaluationSecondSummary : evaluationSecondSummaryList) {
                        if (evaluationSecondSummary.getEvaluationStatus() != 2) {
                            resultSummaryFlag = 0;
                            break;
                        }
                    }
                }
                evaluationReviewItemNode.setResultSummaryFlag(resultSummaryFlag);

                // 剩余项赋值
                evaluationReviewItemNode.setFirstReviewItemId(reviewItemFirstDto.getId());
                evaluationReviewItemNode.setFirstReviewItemType(reviewItemFirstDto.getFirstReviewItemType());
                evaluationReviewItemNode.setSecondReviewItemId(reviewItemSecondDto.getId());
                evaluationReviewItemNode.setSecondReviewItemName(reviewItemSecondDto.getSecondReviewItemName());

                evaluationReviewItemNodeList.add(evaluationReviewItemNode);
                num++;
            }
        }

        return evaluationReviewItemNodeList;
    }

    /**
     * 数据库中初始化专家打分数据
     * @param sectionId
     * @param reviewItemId
     * @param expertId
     * @return
     */
    @Override
    @Transactional
    public void initEvaluationDataForExpert(Long sectionId, Long reviewItemId, Long expertId, String expertName) {
        List<ReviewItemThirdDto> listReviewItemThirdDto = reviewItemThirdService.selectReviewItemThirdListBySecondReviewItemId(reviewItemId);
        if (listReviewItemThirdDto.size() == 0) {
            return;
        }

        // 根据评审项id获取二级评审项信息
        ReviewItemSecond reviewItemSecond = reviewItemSecondService.getById(reviewItemId);

        // 投标人列表
        List<BidSectionTenderDTO> listBidSectionTender = bidSectionTenderService.listDecryptionBidSectionTender(sectionId, 1,1);

        // 生成三级评审数据库中的默认数据
        for (ReviewItemThirdDto reviewItemThirdDto : listReviewItemThirdDto) {
            // 根据评审点id和专家id获取所有公司的评审结果
            List<EvaluationThirdDTO> listEvaluationThirdDTO = evaluationThirdService.resultOfReviewPoint(sectionId, reviewItemThirdDto.getId(), expertId);
            if (listEvaluationThirdDTO.size() > 0) {
                continue;
            }

            // 数据库默认生成空的打分项的数据
            List<EvaluationThird> evaluationThirdList = new ArrayList<>();
            for (BidSectionTenderDTO bidSectionTenderDTO : listBidSectionTender) {
                EvaluationThird evaluationThird = generateEmptyScoreEvaluationThirdObj(reviewItemSecond, reviewItemThirdDto, bidSectionTenderDTO, expertId, expertName);
                evaluationThirdList.add(evaluationThird);
            }
            evaluationThirdService.saveOrUpdateBatch(evaluationThirdList);
        }

        // 生成二级评审数据库中的默认数据。二级评审数据生成改评审项下所有专家的默认数据
        // 查询专家列表
        List<EvaluationCommitteeMembers> evaluationCommitteeMemberList = evaluationCommitteeMembersService.findBySectionId(sectionId);
        for (EvaluationCommitteeMembers evaluationCommitteeMembers : evaluationCommitteeMemberList) {
            Long memberExpertId = evaluationCommitteeMembers.getId();
            String memberExpertName = evaluationCommitteeMembers.getMemberName();

            // 根据标段id、二级评审项id、专家id 查询结果汇总列表，如果列表为空，在数据库中生成默认的汇总列表
            List<EvaluationSecond> evaluationSecondList = evaluationSecondService.findBySectionIdAndExpertIdAndSecondId(sectionId, memberExpertId, reviewItemId);
            if (evaluationSecondList.size() == 0) {
                List<EvaluationSecond> newEvaluationSecondList = new ArrayList<>();
                for (BidSectionTenderDTO bidSectionTenderDTO : listBidSectionTender) {
                    EvaluationSecond evaluationSecond = generateEmptySummaryEvaluationSecondObj(bidSectionTenderDTO, reviewItemSecond, memberExpertId, memberExpertName);
                    newEvaluationSecondList.add(evaluationSecond);
                }
                evaluationSecondService.saveOrUpdateBatch(newEvaluationSecondList);
            }
        }

        // 生成一级汇总表
        evaluationSummaryService.initEvaluationSummary(sectionId);
    }

    /**
     * 生成空分值的 EvaluationThird 对象
     *
     * @return
     */
    private EvaluationThird generateEmptyScoreEvaluationThirdObj(ReviewItemSecond reviewItemSecond,
                                                            ReviewItemThirdDto reviewItemThirdDto,
                                                            BidSectionTenderDTO bidSectionTenderDTO,
                                                            Long expertId,
                                                            String expertName) {
        EvaluationThird evaluationThird = new EvaluationThird();
        evaluationThird.setFileId(reviewItemThirdDto.getFileId());
        evaluationThird.setSecondReviewItemId(reviewItemThirdDto.getSecondReviewItemId());
        evaluationThird.setThirdReviewItemId(reviewItemThirdDto.getId());
        evaluationThird.setSectionId(bidSectionTenderDTO.getSectionId());
        evaluationThird.setExpertId(expertId);
        evaluationThird.setExpertName(expertName);
        evaluationThird.setOrgId(bidSectionTenderDTO.getOrgId());
        evaluationThird.setOrgName(bidSectionTenderDTO.getOrgName());
        evaluationThird.setReviewMode(reviewItemSecond.getReviewMode());
        evaluationThird.setEvaluationStatus(0);
        evaluationThird.setShareFlag(LogicEnum.NO.getCode());
        evaluationThird.setEliminateFlag(LogicEnum.NO.getCode());

        evaluationThird.buildBaseData(1);
        return evaluationThird;
    }

    /**
     * 生成空的 EvaluationSecond 对象
     */
    private EvaluationSecond generateEmptySummaryEvaluationSecondObj(BidSectionTenderDTO bidSectionTenderDTO,
                                                               ReviewItemSecond reviewItemSecond,
                                                               Long expertId,
                                                               String expertName) {
        EvaluationSecond evaluationSecond = new EvaluationSecond();
        evaluationSecond.setFileId(reviewItemSecond.getFileId());
        evaluationSecond.setSecondReviewItemId(reviewItemSecond.getId());
        evaluationSecond.setSectionId(bidSectionTenderDTO.getSectionId());
        evaluationSecond.setExpertId(expertId);
        evaluationSecond.setExpertName(expertName);
        evaluationSecond.setOrgId(bidSectionTenderDTO.getOrgId());
        evaluationSecond.setOrgName(bidSectionTenderDTO.getOrgName());
        evaluationSecond.setReviewMode(reviewItemSecond.getReviewMode());
        evaluationSecond.setEvaluationStatus(0);
        evaluationSecond.setEliminateFlag(LogicEnum.NO.getCode());

        evaluationSecond.buildBaseData(1);
        return evaluationSecond;
    }

    /**
     * 初始化企业淘汰状态
     * @param sectionId 标段id
     * @param reviewItemId 将要初始化的二级评审项id
     * @return
     */
    @Override
    @Transactional
    public Boolean initOrgEliminateStatus(Long sectionId, Long reviewItemId, Long expertId) {
        List<EvaluationReviewItemNode> reviewItemNodeList = createReviewItemFlowNodes(sectionId, expertId);
        ReviewItemSecond reviewItemScond = reviewItemSecondService.getById(reviewItemId);
        ReviewItemFirst reviewItemFirst = reviewItemFirstService.getById(reviewItemScond.getFirstReviewItemId());

        // 如果是初步评审的第一个节点,直接返回
        if (reviewItemNodeList.get(0).getSecondReviewItemId().equals(reviewItemId)) {
            return true;
        }

        // 评审大项类型 1：初步评审 2：详细评审 3：报价评审
        int reviewItemType = reviewItemFirst.getFirstReviewItemType();
        // 当前节点上一个节点
        EvaluationReviewItemNode lastReviewItemNode = null;
        if (reviewItemType == 1) {
            // 当前初始化节点是初步评审节点，查找上一个节点
            for (EvaluationReviewItemNode reviewItemNode : reviewItemNodeList) {
                if (reviewItemNode.getSecondReviewItemId().equals(reviewItemId)) {
                    if (lastReviewItemNode == null) {
                        lastReviewItemNode = reviewItemNode;
                        break;
                    }
                    break;
                } else {
                    lastReviewItemNode = reviewItemNode;
                }
            }
        } else {
            // 当前初始化节点是非初步评审，查找最后一项初步评审的节点
            for (EvaluationReviewItemNode reviewItemNode : reviewItemNodeList) {
                if (reviewItemNode.getFirstReviewItemType().equals(1)) {
                    lastReviewItemNode = reviewItemNode;
                } else {
                    break;
                }
            }
        }

        // 没有初步评审项
        if (lastReviewItemNode == null) {
            return true;
        }

        // 获取淘汰企业的Id列表
        List<Long> orgIdListEliminate = evaluationThirdService.findOrgIdListEliminate(sectionId, lastReviewItemNode.getSecondReviewItemId());

        // 设置二级和三级表的淘汰状态
        evaluationThirdService.saveOrgEliminateStatus(sectionId, reviewItemId, orgIdListEliminate);
        evaluationSecondService.saveOrgEliminateStatus(sectionId, reviewItemId, orgIdListEliminate);

        return true;
    }

    /**
     * 设置复核评审项导致的淘汰状态修改
     * 计算规则：当前节点复核时，如果是初级评审项，该节点及之后的节点都要进行复核。该节点之后的淘汰状态都取消掉。
     * @param sectionId 标段id
     * @param reviewItemId 将要复核的二级评审项id
     * @return
     */
    @Override
    public void recheckResultSummary(Long sectionId, Long reviewItemId, Long expertId) {
        List<EvaluationReviewItemNode> reviewItemNodeList = createReviewItemFlowNodes(sectionId, expertId);
        ReviewItemSecond reviewItemScond = reviewItemSecondService.getById(reviewItemId);
        ReviewItemFirst reviewItemFirst = reviewItemFirstService.getById(reviewItemScond.getFirstReviewItemId());

        // 当前节点状态改为提交
        evaluationSecondService.recheckResultSummary(sectionId,reviewItemId);
        evaluationThirdService.recheckResultSummary(sectionId, reviewItemId);

        // 如果当前节点是非初步评审,只复核当前节点即可
        if (!reviewItemFirst.getFirstReviewItemType().equals(1)) {
            return;
        }

        //
        boolean afterNode = false;
        for (EvaluationReviewItemNode reviewItemNode : reviewItemNodeList) {
            if (reviewItemNode.getSecondReviewItemId().equals(reviewItemId)) {
                afterNode = true;
                continue;
            }
            if (!afterNode) {
                continue;
            }

            Long nodeReviewItemId = reviewItemNode.getSecondReviewItemId();

            // 取消节点淘汰状态
            evaluationSecondService.cancelOrgEliminateStatus(sectionId, nodeReviewItemId);
            evaluationThirdService.cancelOrgEliminateStatus(sectionId, nodeReviewItemId);

            // 节点状态改为提交
            evaluationSecondService.recheckResultSummary(sectionId,nodeReviewItemId);
            evaluationThirdService.recheckResultSummary(sectionId, nodeReviewItemId);
        }

    }

    @Override
    public EvaluationOpeningScheduleVO openingSchedule(Long sectionId) {
        EvaluationOpeningScheduleVO evaluationOpeningScheduleVO = new EvaluationOpeningScheduleVO();

        //获取标段信息
        BidSection bidSection = bidSectionService.getById(sectionId);
        if (bidSection == null) {
            return evaluationOpeningScheduleVO;
        }
        Long fileId = bidSection.getFileId();
        if (fileId == null) {
            return evaluationOpeningScheduleVO;
        }

        //查询所有常用的开标项
        List<BidOpeningSchedule> bidOpeningInfoList = bidOpeningScheduleService.listByFileId(fileId);
        evaluationOpeningScheduleVO.setBidOpeningScheduleList(bidOpeningInfoList);

        // 设置开标一览表结果列表
        List<OpeningBidTender> openingBidTenderList = openingBidTenderService.listDecryptedBySectionId(sectionId);
        evaluationOpeningScheduleVO.setOpeningBidTenderList(openingBidTenderList);

        return evaluationOpeningScheduleVO;
    }
}
